home *** CD-ROM | disk | FTP | other *** search
- unit Status;
-
- { This unit implements a modeless status box in a BorDlg-class dialog. The
- dialog displays three lines of text which may be changed using the dialogs
- Update method. The dialog maintains a boolean field called Continue which is
- set to true in the constructor and becomes false when the user cancels the
- dialog. See the comments below for more details.Complete source, including the
- resource scripts is provided.
-
- To see a TStatusDlg object in action, build and run TEST.PAS included in this
- zipfile.
-
- Contributed by Adam Carney 71150,2436 }
-
-
-
- {$R STATUS.RES}
-
- interface
-
- uses WinTypes, WinProcs, OWindows, ODialogs, Strings;
-
- const {$I CONST.PAS}
-
- type
-
- {INTERFACE ********* TStatusMsg *********************************************}
- PStatusDlg = ^TStatusDlg;
- TStatusDlg = object(TDialog)
- Continue:boolean;
- Title, Message, CancelMsg :PChar;
- constructor Init(AParent:PWindowsObject; ATitle, AMessage, ACancelMsg:PChar);
- procedure SetUpWindow; virtual;
- procedure Update(ItemID:word; Src:PChar);
- procedure ShowItem(ItemID:word; ACmd:integer);
- procedure HandleEvents;
- procedure ChangeButton;
- procedure Complete(CompleteMsg:PChar);
- procedure Cancel(var Msg:TMessage);
- virtual id_First + id_Cancel;
- destructor Done; virtual;
- end;
-
- implementation
- constructor TStatusDlg.Init(AParent:PWindowsObject; ATitle, AMessage, ACancelMsg:PChar);
- { Creates a new dialog object by calling the inherited constructor, sets the
- Continue flag to true and stores three strings on the heap. Title will be used
- to set the dialog caption; Message will be displayed in the first line of the
- dialog; CancelMsg will be displayed in the first line when the box is cancelled }
- begin
- inherited Init(AParent,PChar(StatusDlgRes));
- Continue:=true;
- Title:= StrNew(ATitle);
- Message:= StrNew(AMessage);
- CancelMsg:=StrNew(ACancelMsg);
- end;
-
- procedure TStatusDlg.SetUpWindow;
- { In addition to the inherited SetUpWindow, sets the dialog caption to Title and
- the first line to Message }
- begin
- inherited SetUpWindow;
- SendMessage(HWindow,wm_SetText,0,Longint(Title));
- Update(id_Stat1,Message);
- end;
-
- procedure TStatusDlg.HandleEvents;
- { Allows message processing while the host procedure is running. Called by Update,
- HandleEvents is required in order to allow the user to click the Cancel button
- or otherwise terminate the host process by typing escape or by choosing close
- from the dialog's system menu }
- var
- Msg:TMsg;
- begin
- while PeekMessage(Msg,0,0,0,pm_Remove) do
- if not IsDialogMessage(HWindow,Msg) then
- begin
- TranslateMessage(Msg);
- DispatchMessage(Msg);
- end;
- end;
-
- procedure TStatusDlg.Update(ItemID:word; Src:PChar);
- { Changes the text of the item with id of ItemID to that addressed by Src.
- ItemID should be one of the constants id_Stat1, id_Stat2 or id_Stat3 to
- change the displayed text of the first, second or third lines, respectively.
- Calls HandleEvents to process all messages posted in the application queue
- since the last call to Update }
- begin
- SendMessage(GetDlgItem(HWindow,ItemID),wm_SetText,0,LongInt(Src));
- HandleEvents;
- end;
-
- procedure TStatusDlg.ShowItem(ItemID:word; ACmd:integer);
- { Sets the visible state of an Item. ShowItem is used to hide/display the OK and
- Cancel buttons (which overlie each other) and lines of text in the dialog }
- begin
- ShowWindow(GetDlgItem(HWindow,ItemID),ACmd);
- end;
-
- procedure TStatusDlg.ChangeButton;
- { Hides the Cancel button and Shows the OK button. Has the appearance
- of changing the Cancel button to an OK button }
- begin
- ShowItem(id_Cancel,sw_Hide);
- ShowItem(id_OK,sw_Show);
- end;
-
- procedure TStatusDlg.Cancel(var Msg:TMessage);
- { Sets Continue to false, Sets first line to CancelMsg, hides 2nd and 3rd lines
- of text and changes buttons.
- Note: If continue is already false (not first time Cancel has been called) then
- the inherited method is called to close the dialog box. This is reqired so that
- the user can close the terminated status box using the escape key or the dialog's
- system menu. }
- begin
- if Continue then
- begin
- Continue:=false;
- Update(id_Stat1,CancelMsg);
- ShowItem(id_Stat2,sw_Hide);
- ShowItem(id_Stat3,sw_Hide);
- ChangeButton;
- end
- else
- inherited Cancel(Msg);
- end;
-
- procedure TStatusDlg.Complete(CompleteMsg:PChar);
- { Call update when the host procedure is finished. It changes the first line to
- CompleteMsg, hides lines 2 and 3 and changes the Cancel button to OK }
- begin
- Update(id_Stat1,CompleteMsg);
- ShowItem(id_Stat2,sw_Hide);
- ShowItem(id_Stat3,sw_Hide);
- ChangeButton;
- end;
-
- destructor TStatusDlg.Done;
- { Disposes of the Title, Messge and CancelMsg strings before calling the inherited
- destructor }
- begin
- StrDispose(Title);
- StrDispose(Message);
- StrDispose(CancelMsg);
- inherited Done;
- end;
-
- end.